<?php
    /**
    * Meeting Approve
    */
    if (!defined('EXPONENT')) exit('');
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate","meeting","meeting_assistant"),exponent_core_makeLocation("profilemodule","_syscore","")))
    {
        $meeting=null;
        if (isset($_REQUEST['id']))
        {
            $meeting=$db->selectObject('profilemodule_meeting','id='.intval($_REQUEST['id']));
        }
        if (isset($meeting->id))
        {
            $content = $_REQUEST['content'];
            $subject = $_REQUEST['subject'];
            global $user;       
            
            $mail_list=array();
            $mail_list[] = $meeting->email;            
            $reply=null;
            $reply->meeting_id=$meeting->id;            
            $reply->sender=$user->id;
            $reply->target=$meeting->email;
            $reply->subject=$subject;
            $reply->body = $content;
            $reply->send_on=time();
            $db->insertObject($reply,'profilemodule_meeting_reply');  
            profilemodule::_meeting_history_add($meeting->id,'Reply subject: '.$reply->subject."; Reply content: ".$reply->body,'Reply');
            
            $send_admin=profilemodule::SendMail($subject, $content, 0, $mail_list, true,$user->email ,$user->firstname." ".$user->lastname);
            if ($send_admin)
                echo "OK";
            // update meeting

            $meeting->last_update = time();
            $meeting->last_update_by = $meeting->approve_by;
            
            $db->updateObject($meeting,'profilemodule_meeting');  
        }
        else
        {
            echo "";
        }
    }
    else
        exponent_http_error(403);

?>
